package com.demo.task.handler

import android.content.Context
import android.content.Intent
import android.util.Log
import com.demo.task.ui.MainActivity
import com.orhanobut.logger.Logger


class GlobalExceptionHandler(
    private val context: Context
) : Thread.UncaughtExceptionHandler {
    override fun uncaughtException(t: Thread, e: Throwable) {
        Log.e(TAG, "uncaughtException: ", e)
        Logger.e(e, "uncaughtException: ")
        //restartApp()
    }

    private fun restartApp() {
        val intent = Intent(context, MainActivity::class.java)
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        context.startActivity(intent)
    }

    companion object {
        private const val TAG = "GlobalExceptionHandler"
    }
}
